*********************************************************************************
*							Bunching figures				*
*							Jennifer Mayo									*
*							Date: 14/04/2021									*
*********************************************************************************

clear
set more off

global name "jmp4k"
global home "/Users/$name/Library/CloudStorage/OneDrive-UniversityofMissouri/Projects/Navigating the notches"
global data "$home/Replication"
global output "$home/CN Output"

use "$data/Overall score.dta", clear
set scheme s1mono


*********************************************************************************

gen near4star = inrange(score,85,95)
	la var near4star "Overall score between 85 and 95"
	
*	Collapse Data into counts of firms by score bins				

	drop if PublicationYear==2011  
	drop if PublicationYear==2016  // drop years method changed
	duplicates drop

	egen double scoregroups = cut(score), at(0 (0.2) 100)

collapse (count) score , by(scoregroups)   //score is raw score; scoregroups = rounded scores
drop if scoregroups<83

gen scoregroups2 = scoregroups^2
gen scoregroups3 = scoregroups^3
gen scoregroups4 = scoregroups^4
gen counterfactual = -307864.6 + (scoregroups*9604.017) + (scoregroups2*-98.67636) + (scoregroups3*0.3342987) + (scoregroups4*0)

label var counterfactual "Counterfactual density"
label var score "Binned counts"

****************
**  FIGURE 5  **
****************

graph twoway (scatter score scoregroups, msymbol(Oh)) (line counterfactual scoregroups), xline(90, lpattern(dash) lstyle(foreground)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle("Raw score") ytitle("Count of organizations")  note("Note: The dashed line represents the 4-star threshold")	legend(ring(0) pos(7) cols(1) size(*0.6) rowgap(*0.1) symxsize(*0.6) region(style(none)))

graph export "$output/Figure5.eps", replace

















